CSS @scroll-timelineã®å æ¬çãªã¬ã€ããæ§æãããããã£ãäœ¿çšæ³ãé«åºŠãªã¢ãã¡ãŒã·ã§ã³æè¡ã解説ãçŸä»£çãªWebäœéšã®ããã®é åçãªã¹ã¯ããŒã«é§ååã¢ãã¡ãŒã·ã§ã³ã®äœææ¹æ³ãåŠã³ãŸãã
Mastering CSS @scroll-timeline: Animation Control Through Scroll Progress
Webéçºã®çµ¶ãéãªãé²åã®äžã§ãé
åçã§ã€ã³ã¿ã©ã¯ãã£ããªãŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ã®æ§ç¯ã¯æãéèŠã§ããCSSã¯ãããå®çŸããããã®ããŸããŸãªããŒã«ãæäŸããŠããŸãããæã匷åã§ãããªããèŠéããããã¡ãªãã®ã®1ã€ã@scroll-timeline at-ruleã§ãããã®æ©èœã«ãããéçºè
ã¯ã¢ãã¡ãŒã·ã§ã³ãèŠçŽ ã®ã¹ã¯ããŒã«ã®é²è¡ã«çŽæ¥çµã³ä»ããé
åçãªã¹ã¯ããŒã«é§ååã¢ãã¡ãŒã·ã§ã³ãäœæã§ããŸãããã®èšäºã§ã¯ã@scroll-timelineã®æ§æãããããã£ãå®çšçãªäœ¿çšæ³ãããã³é«åºŠãªã¢ãã¡ãŒã·ã§ã³æè¡ãç¶²çŸ
çã«è§£èª¬ããWebãã¶ã€ã³ãåäžãããŸãã
What is CSS @scroll-timeline?
@scroll-timelineã¯ãã¹ã¯ããŒã«ã¿ã€ã ã©ã€ã³ãå®çŸ©ããCSS at-ruleã§ããããã¯ãæå®ãããèŠçŽ ã®ã¹ã¯ããŒã«äœçœ®ã«å¯Ÿå¿ããäžé£ã®ç¶æ
ã§ããåŸæ¥ã®æéããŒã¹ã®ã¢ãã¡ãŒã·ã§ã³ã«äŸåãã代ããã«ã@scroll-timelineã¯ã¢ãã¡ãŒã·ã§ã³ã®é²è¡ããŠãŒã¶ãŒã®ã¹ã¯ããŒã«ã¢ã¯ã·ã§ã³ã«ãªã³ã¯ãããŸããããã«ãããã¢ãã¡ãŒã·ã§ã³ã®é床ããŠãŒã¶ãŒã®ã¹ã¯ããŒã«åäœã«ãã£ãŠçŽæ¥å¶åŸ¡ããããããããèªç¶ã§å¿çæ§ã®é«ãã¢ãã¡ãŒã·ã§ã³ãå®çŸããŸãã
ããã«ãããæ¬¡ã®ãšããµã€ãã£ã³ã°ãªå¯èœæ§ãéãããŸãã
- Visual storytelling: ãŠãŒã¶ãŒãã¹ã¯ããŒã«ããã«ã€ããŠãã³ã³ãã³ããæ®µéçã«è¡šç€ºããŸãã
- Interactive data visualization: ãŠãŒã¶ãŒãããŒã¿ãæ¢çŽ¢ããã«ã€ããŠãã°ã©ããã°ã©ããã¢ãã¡ãŒã·ã§ã³åããŸãã
- Parallax effects: ã¹ã¯ããŒã«äœçœ®ã«åºã¥ããŠãç°ãªãèŠçŽ ãããŸããŸãªé床ã§ã¢ãã¡ãŒã·ã§ã³åããããšã«ããã奥è¡ããšæ¬¡å ãäœæããŸãã
- Progress indicators: é·ãããã¥ã¡ã³ãã«ããããŠãŒã¶ãŒã®é²è¡ç¶æ³ãèŠèŠçã«è¡šããŸãã
Syntax and Properties
@scroll-timeline at-ruleã®åºæ¬çãªæ§æã¯æ¬¡ã®ãšããã§ãã
@scroll-timeline timeline-name {
source: auto | <element-selector>;
orientation: auto | block | inline;
scroll-offsets: <scroll-offset>[ , <scroll-offset> ]*;
}
åããããã£ãåè§£ããŠã¿ãŸãããã
timeline-name
ããã¯ãã¹ã¯ããŒã«ã¿ã€ã ã©ã€ã³ã®äžæã®èå¥åã§ããã¢ãã¡ãŒã·ã§ã³ã«é©çšãããšãã«ããã®ååã䜿çšããŠã¿ã€ã ã©ã€ã³ãåç §ããŸãã
Example:
@scroll-timeline my-scroll-timeline {
/* ... */
}
source
ãã®ããããã£ã¯ãã¢ãã¡ãŒã·ã§ã³ãé§åããã¹ã¯ããŒã«äœçœ®ã®èŠçŽ ãæå®ããŸããæ¬¡ã®2ã€ã®å€ããããŸãã
auto: ãã©ãŠã¶ã¯ã¹ã¯ããŒã«èŠçŽ ãèªåçã«æ±ºå®ããŸããããã¯å€ãã®å Žåãããã¥ã¡ã³ãã®ãã¥ãŒããŒãïŒãã©ãŠã¶ãŠã£ã³ããŠïŒã§ãã<element-selector>: ã¹ã¯ããŒã«ãœãŒã¹ãšããŠäœ¿çšããç¹å®ã®èŠçŽ ãèå¥ããCSSã»ã¬ã¯ã¿ãŒãããã«ãããããŒãžäžã®ç¹å®ã®ã³ã³ãããŸãã¯ã»ã¯ã·ã§ã³ãã¿ãŒã²ããã«ããããšãã§ããŸãã
Example (using the viewport as the source):
@scroll-timeline my-scroll-timeline {
source: auto; /* Uses the viewport */
/* ... */
}
Example (using a specific element as the source):
@scroll-timeline my-scroll-timeline {
source: #scrollable-container; /* Uses the element with ID "scrollable-container" */
/* ... */
}
orientation
ãã®ããããã£ã¯ãã¿ã€ã ã©ã€ã³ã«äœ¿çšããã¹ã¯ããŒã«æ¹åãæå®ããŸããã¢ãã¡ãŒã·ã§ã³ãåçŽã¹ã¯ããŒã«ãŸãã¯æ°Žå¹³ã¹ã¯ããŒã«ã®ã©ã¡ãã«ãã£ãŠé§åãããããæ±ºå®ããŸããæ¬¡ã®3ã€ã®å€ããããŸãã
auto: ãã©ãŠã¶ã¯ããœãŒã¹èŠçŽ ã®äž»èŠãªã¹ã¯ããŒã«æ¹åã«åºã¥ããŠã¹ã¯ããŒã«æ¹åãèªåçã«æ±ºå®ããŸããblock: ãããã¯ïŒã»ãšãã©ã®æžã蟌ã¿ã¢ãŒãã§ã¯åçŽïŒã¹ã¯ããŒã«æ¹åã䜿çšããŸããinline: ã€ã³ã©ã€ã³ïŒã»ãšãã©ã®æžã蟌ã¿ã¢ãŒãã§ã¯æ°Žå¹³ïŒã¹ã¯ããŒã«æ¹åã䜿çšããŸãã
Example (using vertical scrolling):
@scroll-timeline my-scroll-timeline {
source: auto;
orientation: block; /* Vertical scrolling */
/* ... */
}
Example (using horizontal scrolling):
@scroll-timeline my-scroll-timeline {
source: #horizontal-scroll-container;
orientation: inline; /* Horizontal scrolling */
/* ... */
}
scroll-offsets
ãã®ããããã£ã¯ãã¢ãã¡ãŒã·ã§ã³ã®ç¹å®ã®ãã€ã³ãã«å¯Ÿå¿ããã¹ã¯ããŒã«äœçœ®ãå®çŸ©ããŸããããã¯ãªãã·ã§ã³ã®ããããã£ã§ãããæå®ããªãå Žåãã¢ãã¡ãŒã·ã§ã³ã¯ã¹ã¯ããŒã«å¯èœãªé åã®æåããæåŸãŸã§åçãããŸãã䜿çšããå Žåã¯ã1ã€ä»¥äžã®ã¹ã¯ããŒã«ãªãã»ãããå®çŸ©ã§ããŸãããããããã¹ã¯ããŒã«äœçœ®ãšã¢ãã¡ãŒã·ã§ã³ã®é²è¡ã®å¯Ÿå¿ãããã€ã³ããæå®ããŸãã
<scroll-offset>ã®æ§æã¯æ¬¡ã®ãšããã§ãã
<scroll-offset> = <length-percentage> [ at <length-percentage> ]
Where:
- æåã®
<length-percentage>ã¯ãã¹ã¯ããŒã«å¯èœãªé åå ã®ã¹ã¯ããŒã«äœçœ®ã衚ããŸãã - ãªãã·ã§ã³ã®
at <length-percentage>ã¯ã察å¿ããã¢ãã¡ãŒã·ã§ã³ã®é²è¡ç¶æ³ïŒ0ïŒ ã100ïŒ ïŒã衚ããŸããçç¥ããå Žåãã¢ãã¡ãŒã·ã§ã³ã®é²è¡ç¶æ³ã¯ãå®çŸ©ãããã¹ã¯ããŒã«ãªãã»ããéã§åçã«åæ£ãããŸãã
Examples:
/* Scroll position 200px corresponds to animation progress 0% */
scroll-offsets: 200px at 0%;
/* Scroll position at 50% of the scrollable area corresponds to animation progress 50% */
scroll-offsets: 50% at 50%;
/* Multiple offsets: */
scroll-offsets: 0px at 0%, 500px at 50%, 1000px at 100%;
/* Without the "at" keyword - evenly distributed animation progress: */
scroll-offsets: 0px, 500px, 1000px; /* Equivalent to 0px at 0%, 500px at 50%, 1000px at 100% */
Important Considerations for scroll-offsets:
- If you specify
scroll-offsets, ensure that they cover the range of the scrollable area to avoid unexpected animation behavior. - The animation progress is interpolated between the defined scroll offsets.
- If you don't specify
scroll-offsets, the animation progress will be evenly distributed across the entire scrollable area.
Applying the Scroll Timeline to an Animation
ã¹ã¯ããŒã«ã¿ã€ã ã©ã€ã³ãå®çŸ©ããããanimation-timelineããããã£ã䜿çšããŠCSSã¢ãã¡ãŒã·ã§ã³ã«é©çšããå¿
èŠããããŸãã
æ§æã¯ç°¡åã§ãã
animation-timeline: timeline-name; /* Use the name you defined in @scroll-timeline */
@keyframesã䜿çšããŠæšæºã®CSSã¢ãã¡ãŒã·ã§ã³ãå®çŸ©ããå¿
èŠããããŸããã¢ãã¡ãŒã·ã§ã³ã¯ããŠãŒã¶ãŒãã¹ã¯ããŒã«ãããšãã«çºçããCSSããããã£ã®å€æŽãå®çŸ©ããŸããããã«ã`animation-range` CSSããããã£ãèšå®ãããŠããããšã確èªããå¿
èŠããããŸããããã¯ãã¢ãã¡ãŒã·ã§ã³ãã¢ã¯ãã£ãã«ããã¹ã¯ããŒã«ã¿ã€ã ã©ã€ã³ã®ç¯å²ãå®çŸ©ããŸãã
å®å šãªäŸã次ã«ç€ºããŸãã
/* Define the scroll timeline */
@scroll-timeline my-scroll-timeline {
source: auto;
orientation: block;
}
/* Define the animation */
@keyframes fade-in {
0% {
opacity: 0;
transform: translateY(20px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
/* Apply the animation and scroll timeline to an element */
.animated-element {
animation: fade-in 1s forwards;
animation-timeline: my-scroll-timeline;
animation-range: entry 25% cover 75%; /* entry and cover are keyword values for the start and end ranges */
}
In this example:
my-scroll-timelineãšããååã®@scroll-timelineãå®çŸ©ããããã¥ãŒããŒãããœãŒã¹ãšããŠãåçŽã¹ã¯ããŒã«ãæ¹åãšããŠäœ¿çšããŸããfade-inãšããååã®@keyframesã¯ãåçŽãªãã§ãŒãã€ã³ããã³ã¹ã©ã€ãã¢ããã¢ãã¡ãŒã·ã§ã³ãå®çŸ©ããŸãã.animated-elementã¯ã©ã¹ã«ã¯fade-inã¢ãã¡ãŒã·ã§ã³ãé©çšãããŸãããã¿ã€ããŒã«ãã£ãŠããªã¬ãŒããã代ããã«ãmy-scroll-timelineã«ãã£ãŠå¶åŸ¡ãããŸãã- animation-rangeã¯ãèŠçŽ ã®äžç«¯ããã¥ãŒããŒãã®äžéš25ïŒ ã«å ¥ã£ããšãã«ã¢ãã¡ãŒã·ã§ã³ãéå§ããäžéš25ïŒ ããé¢ãããšãã«çµäºããå¿ èŠãããããšãå®çŸ©ããŸãã
Practical Examples and Use Cases
@scroll-timelineã䜿çšããŠé
åçãªWebãšã¯ã¹ããªãšã³ã¹ãäœæããæ¹æ³ã®å®çšçãªäŸãããã€ãèŠãŠã¿ãŸãããã
1. Progressively Revealing Content
ããã¯ããŠãŒã¶ãŒãããŒãžãäžã«ã¹ã¯ããŒã«ããã«ã€ããŠã³ã³ãã³ãã衚瀺ããäžè¬çãªãŠãŒã¹ã±ãŒã¹ã§ããã»ã¯ã·ã§ã³ã衚瀺ãããã«ã€ããŠãã§ãŒãã€ã³ããé·ã圢åŒã®èšäºãæ³åããŠãã ããã
HTML:
<section class="content-section">
<h2>Section 1</h2>
<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit...</p>
</section>
<section class="content-section">
<h2>Section 2</h2>
<p>Sed do eiusmod tempor incididunt ut labore et dolore magna aliqua...</p>
</section>
CSS:
@scroll-timeline reveal-timeline {
source: auto;
orientation: block;
}
@keyframes reveal {
0% {
opacity: 0;
transform: translateY(20px);
}
100% {
opacity: 1;
transform: translateY(0);
}
}
.content-section {
animation: reveal 1s forwards;
animation-timeline: reveal-timeline;
animation-range: entry 25% cover 75%;
}
ãã®äŸã§ã¯ãå.content-sectionã¯ããã¥ãŒããŒãã«ã¹ã¯ããŒã«ããã«ã€ããŠãã§ãŒãã€ã³ããŸãã`animation-range`ã¯ãã»ã¯ã·ã§ã³ã®äžç«¯ããã¥ãŒããŒãã®äžéš25ïŒ
ã«å
¥ã£ããšãã«ã¢ãã¡ãŒã·ã§ã³ãéå§ãããã»ã¯ã·ã§ã³ãäžéš25ïŒ
ããé¢ãããšãã«çµäºããããšãä¿èšŒããŸãã
2. Parallax Effects
èŠå·®å¹æã¯ãèæ¯èŠçŽ ã忝èŠçŽ ãããç°ãªãé床ã§ç§»åãããããšã«ããã奥è¡ãæãçã¿åºããŸãã@scroll-timelineã䜿çšãããšãèŠå·®ã¹ã¯ããŒã«ãç°¡åã«å®è£
ã§ããŸãã
HTML:
<div class="parallax-container">
<div class="background-element"></div>
<div class="foreground-element">
<h2>Parallax Section</h2>
<p>Some content here...</p>
</div>
</div>
CSS:
.parallax-container {
position: relative;
height: 500px; /* Adjust as needed */
overflow: hidden;
}
.background-element {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
background-image: url('background.jpg'); /* Replace with your image */
background-size: cover;
transform: translateZ(-1px) scale(2); /* Creates the parallax effect */
transform-origin: top;
pointer-events: none; /* Allows clicking on foreground elements */
animation: parallax-bg 1s linear forwards;
animation-timeline: parallax-timeline;
animation-range: 0vh 100vh;
}
.foreground-element {
position: relative;
z-index: 1;
padding: 50px;
background-color: rgba(255, 255, 255, 0.8);
}
@scroll-timeline parallax-timeline {
source: auto;
orientation: block;
}
@keyframes parallax-bg {
0% { transform: translateZ(-1px) scale(2) translateY(0px); }
100% { transform: translateZ(-1px) scale(2) translateY(-50vh); }
}
ãã®äŸã§ã¯ã.background-elementã¯.foreground-elementã®èé¢ã«é
眮ãããtransformã䜿çšããŠæ¡å€§çž®å°ãããŸããæ¬¡ã«ã`parallax-bg`ã¢ãã¡ãŒã·ã§ã³ãé©çšããããŠãŒã¶ãŒãã¹ã¯ããŒã«ãããšèæ¯ã忝ãããé
ãç§»åããèŠå·®å¹æãçãŸããŸãã`animation-range`ã¯ãã¢ãã¡ãŒã·ã§ã³ããã¥ãŒããŒãã®å
šé«ïŒ0vhãã100vhïŒã«ããã£ãŠå®è¡ãããããšãä¿èšŒããŸãã
3. Animating a Progress Bar
@scroll-timelineã䜿çšããŠãããã¥ã¡ã³ãã®ã¹ã¯ããŒã«é²è¡ç¶æ³ãèŠèŠçã«è¡šãããã°ã¬ã¹ããŒãäœæã§ããŸãã
HTML:
<div class="progress-bar-container">
<div class="progress-bar"></div>
</div>
<div class="content">
<!-- Your content here -->
</div>
CSS:
.progress-bar-container {
position: fixed;
top: 0;
left: 0;
width: 100%;
height: 5px;
background-color: #eee;
z-index: 1000;
}
.progress-bar {
height: 100%;
width: 0%;
background-color: #007bff;
animation: progress-bar-fill 1s linear forwards;
animation-timeline: document-scroll-timeline;
}
@scroll-timeline document-scroll-timeline {
source: auto;
orientation: block;
}
@keyframes progress-bar-fill {
0% {
width: 0%;
}
100% {
width: 100%;
}
}
ãã®äŸã§ã¯ããŠãŒã¶ãŒãããã¥ã¡ã³ããã¹ã¯ããŒã«ãããšã.progress-barã®å¹
ã0ïŒ
ãã100ïŒ
ã«ã¢ãã¡ãŒã·ã§ã³åãããŸãã@scroll-timelineã¯`document-scroll-timeline`ãšããååã§ããããäœã衚ãããæç¢ºã«ããŠããŸãã
Advanced Techniques
åºæ¬ãçè§£ããããé«åºŠãªãã¯ããã¯ã調ã¹ãŠãããã«æŽç·Žãããã¹ã¯ããŒã«é§ååã¢ãã¡ãŒã·ã§ã³ãäœæã§ããŸãã
1. Using scroll-offsets for Precise Control
scroll-offsetsããããã£ã䜿çšãããšãç¹å®ã®ã¹ã¯ããŒã«äœçœ®ãç¹å®ã®ã¢ãã¡ãŒã·ã§ã³é²è¡å€ã«ãããã§ããŸããããã¯ãã¹ã¯ããŒã«äžã«ç¹å®ã®ãã€ã³ãã§ç¹å®ã®ã¢ãã¡ãŒã·ã§ã³ç¶æ
ãããªã¬ãŒããå Žåã«åœ¹ç«ã¡ãŸãã
@scroll-timeline custom-timeline {
source: #scrollable-container;
orientation: block;
scroll-offsets: 100px at 0%, 500px at 50%, 1000px at 100%;
}
@keyframes custom-animation {
0% {
transform: translateX(-100px);
opacity: 0;
}
50% {
transform: translateX(0);
opacity: 1;
}
100% {
transform: translateX(100px);
opacity: 0;
}
}
.animated-element {
animation: custom-animation 1s forwards;
animation-timeline: custom-timeline;
}
ãã®äŸã§ã¯ãã¢ãã¡ãŒã·ã§ã³ã¯æ¬¡ã®ããã«ãªããŸãã
- ã¹ã¯ããŒã«äœçœ®ã100pxã®å Žåã
translateX(-100px)ããã³opacity: 0ã§éå§ããŸãã - ã¹ã¯ããŒã«äœçœ®ã500pxã®å Žåã
translateX(0)ããã³opacity: 1ã«éããŸãã - ã¹ã¯ããŒã«äœçœ®ã1000pxã®å Žåã
translateX(100px)ããã³opacity: 0ã§çµäºããŸãã
2. Combining with JavaScript
@scroll-timelineã¯CSSãä»ããŠåŒ·åãªã¢ãã¡ãŒã·ã§ã³å¶åŸ¡ãæäŸããŸãããJavaScriptãšçµã¿åãããŠãããã«æè»æ§ãé«ããããšãã§ããŸããããšãã°ãJavaScriptã䜿çšããŠã次ã®ããšãè¡ãå ŽåããããŸãã
- ãã¥ãŒããŒããµã€ãºãŸãã¯ã³ã³ãã³ãã®å€æŽã«åºã¥ããŠã
scroll-offsetsãåçã«èšç®ããŠæŽæ°ããŸãã - ã¹ã¯ããŒã«ã®é²è¡ã«åºã¥ããŠã远å ã®JavaScriptããŒã¹ã®ãšãã§ã¯ããŸãã¯ã€ã³ã¿ã©ã¯ã·ã§ã³ãããªã¬ãŒããŸãã
@scroll-timelineãå®å šã«ãµããŒãããŠããªããã©ãŠã¶ã®ãã©ãŒã«ããã¯ãœãªã¥ãŒã·ã§ã³ãå®è£ ããŸãã
JavaScriptã䜿çšããŠã¹ã¯ããŒã«ã®é²è¡ç¶æ³ãèªã¿åããCSS倿°ãæŽæ°ããåºæ¬çãªäŸã次ã«ç€ºããŸãã
const scrollableElement = document.getElementById('scrollable-container');
const animatedElement = document.querySelector('.animated-element');
scrollableElement.addEventListener('scroll', () => {
const scrollPosition = scrollableElement.scrollTop;
const maxScroll = scrollableElement.scrollHeight - scrollableElement.clientHeight;
const scrollPercentage = (scrollPosition / maxScroll) * 100;
animatedElement.style.setProperty('--scroll-progress', scrollPercentage + '%');
});
次ã«ããã®CSS倿°ãã¢ãã¡ãŒã·ã§ã³å ã§äœ¿çšã§ããŸãã
@keyframes custom-animation {
0% {
transform: translateX(calc(var(--scroll-progress) * -1px));
}
100% {
transform: translateX(calc(var(--scroll-progress) * 1px));
}
}
.animated-element {
--scroll-progress: 0%; /* Initial value */
animation: custom-animation 1s linear forwards;
animation-timeline: scroll-driven-timeline;
}
3. Leveraging Different Easing Functions
animation-timing-functionã¯ã¹ã¯ããŒã«ã¿ã€ã ã©ã€ã³èªäœã«ã¯çŽæ¥é©çšã§ããŸãããïŒã¿ã€ã ã©ã€ã³ã¯æéã§ã¯ãªãã¹ã¯ããŒã«ã®é²è¡ã«ãã£ãŠé§åãããããïŒã@keyframeså
ã§ã€ãŒãžã³ã°é¢æ°ã䜿çšããŠãã¢ãã¡ãŒã·ã§ã³ã®é床ãšãªãºã ãããŸããŸãªæ®µéã§å¶åŸ¡ã§ããŸããease-inãease-outãease-in-outãªã©ã®ããŸããŸãªã€ãŒãžã³ã°é¢æ°ããã«ã¹ã¿ã ã®ãã¥ãŒããã¯ããžãšæ²ç·ã䜿çšããŠãç®çã®å¹æãå®çŸããŸãã
Browser Compatibility and Fallbacks
2023幎åŸåã®æç¹ã§ã@scroll-timelineã¯ãChromeãEdgeãFirefoxãSafariãªã©ã®ææ°ã®ãã©ãŠã¶ã§æ¯èŒçåªãããã©ãŠã¶ãµããŒããåããŠããŸãããã ããæ¬çªç°å¢ã«å®è£
ããåã«ãCan I use...ãªã©ã®Webãµã€ãã§çŸåšã®äºææ§ã¹ããŒã¿ã¹ã確èªããããšãéèŠã§ãã
@scroll-timelineããµããŒãããŠããªããã©ãŠã¶ã®å Žåã¯ãåŸæ¥ã®JavaScriptããŒã¹ã®ã¹ã¯ããŒã«ã€ãã³ããªã¹ããŒãšãGSAPïŒGreenSock Animation PlatformïŒãAnime.jsãªã©ã®ã¢ãã¡ãŒã·ã§ã³ã©ã€ãã©ãªã䜿çšããŠãã©ãŒã«ããã¯ãæäŸã§ããŸããCSSæ©èœã¯ãšãªïŒ@supportsïŒã䜿çšããŠã@scroll-timelineããŒã¹ã®ã¢ãã¡ãŒã·ã§ã³ãŸãã¯JavaScriptããŒã¹ã®ãã©ãŒã«ããã¯ãæ¡ä»¶ä»ãã§é©çšããããšãã§ããŸãã
@supports (animation-timeline: scroll()) {
/* Apply @scroll-timeline-based animations */
.animated-element {
animation: fade-in 1s forwards;
animation-timeline: my-scroll-timeline;
}
} @else {
/* Apply JavaScript-based fallback */
.animated-element {
/* Hide initially */
opacity: 0;
}
/* (JavaScript code to detect scroll and apply opacity) */
}
Accessibility Considerations
@scroll-timelineãŸãã¯ãã®ä»ã®ã¢ãã¡ãŒã·ã§ã³æè¡ã䜿çšããå Žåã¯ãã¢ã¯ã»ã·ããªãã£ãèæ
®ããããšãéèŠã§ããã¢ãã¡ãŒã·ã§ã³ã次ã®åå ã«ãªããªãããã«ããŠãã ããã
- Seizures: ç¹æ» ãŸãã¯æ¥éã«å€åããã¢ãã¡ãŒã·ã§ã³ã¯é¿ããŠãã ããã
- Distraction: ç¹ã«ã¢ãã¡ãŒã·ã§ã³ãé·ããŠæ°ãæ£ãå Žåã¯ããŠãŒã¶ãŒãã¢ãã¡ãŒã·ã§ã³ãäžæåæ¢ãŸãã¯ç¡å¹ã«ããæ¹æ³ãæäŸããŸãã
- Cognitive overload: ã¢ãã¡ãŒã·ã§ã³ã¯æ§ããã«äœ¿çšããçŽç²ã«è£ 食çã§ããã ãã§ãªããæç¢ºãªç®çãæããããã«ããŠãã ããã
- Motion sickness: äžéšã®ãŠãŒã¶ãŒã§ä¹ãç©é ããåŒãèµ·ããå¯èœæ§ããããããèŠå·®å¹æã«æ³šæããŠãã ããã
éçãªã³ã³ãã³ãã説æçãªããã¹ããªã©ãã¢ãã¡ãŒã·ã§ã³ãä»ããŠæç€ºãããæ å ±ã«ã¢ã¯ã»ã¹ããããã®ä»£æ¿æ¹æ³ãæäŸããããšãæ€èšããŠãã ãããARIA屿§ã䜿çšããŠãæ¯æŽæè¡ã«ã»ãã³ãã£ãã¯ãªæå³ãšã³ã³ããã¹ããæäŸããŸãã
Best Practices
@scroll-timelineã䜿çšããéã«çæãã¹ããã¹ããã©ã¯ãã£ã¹ã次ã«ç€ºããŸãã
- Use descriptive timeline names: ç®çãæç¢ºã«ç€ºãã¿ã€ã ã©ã€ã³åãéžæããŸãïŒäŸïŒ
parallax-background-timelineãreveal-section-timelineïŒã - Keep animations performant: ããã©ãŒãã³ã¹ã®ããã«ããã¯ãåé¿ããããã«ãã¢ãã¡ãŒã·ã§ã³ãæé©åããŸããå¯èœãªéãã
transformãopacityãªã©ã®ããŒããŠã§ã¢ã¢ã¯ã»ã©ã¬ãŒã·ã§ã³CSSããããã£ã䜿çšããŸãã - Test thoroughly: ããŸããŸãªããã€ã¹ãšãã©ãŠã¶ã§ã¢ãã¡ãŒã·ã§ã³ããã¹ãããŠãæåŸ ã©ããã«åäœããã¢ã¯ã»ã·ããªãã£ãããã©ãŒãã³ã¹ã®åé¡ãçºçããªãããšã確èªããŸãã
- Start Simple: ã·ã³ãã«ãªã¢ãã¡ãŒã·ã§ã³ããå§ããŠãçµéšãç©ãã«ã€ããŠåŸã ã«è€éããå¢ããŠãããŸãã
- Consider the User Experience: ã¢ãã¡ãŒã·ã§ã³ããŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ãåäžãããããšã確èªããæãªããªãããã«ããŠãã ãããé床ã«è€éãŸãã¯æ°ãæ£ãã¢ãã¡ãŒã·ã§ã³ã¯é¿ããŠãã ããã
- Use the `animation-range` CSS property: èŠçŽ ãã¹ã ãŒãºã§äºæž¬å¯èœãªãšã¯ã¹ããªãšã³ã¹ã®ããã«ãã¥ãŒããŒãã«ããå Žåã«ã®ã¿ã¢ãã¡ãŒã·ã§ã³ãããªã¬ãŒãããããã«ããŸãã
Conclusion
@scroll-timelineã¯ãéçºè
ãé
åçã§ã€ã³ã¿ã©ã¯ãã£ããªã¹ã¯ããŒã«é§ååã¢ãã¡ãŒã·ã§ã³ãäœæã§ãã匷åãªCSSæ©èœã§ããã¢ãã¡ãŒã·ã§ã³ããŠãŒã¶ãŒã®ã¹ã¯ããŒã«åäœã«ãªã³ã¯ãããããšã§ãããèªç¶ã§å¿çæ§ã®é«ãWebãšã¯ã¹ããªãšã³ã¹ãäœæã§ããŸããæ§æãããããã£ãããã³é«åºŠãªãã¯ããã¯ãçè§£ããããšã§ã@scroll-timelineãæŽ»çšããŠWebãã¶ã€ã³ãåäžãããé
åçãªãŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ãäœæã§ããŸãã@scroll-timelineãå®è£
ãããšãã¯ããã©ãŠã¶ã®äºææ§ãã¢ã¯ã»ã·ããªãã£ãããã³ããã©ãŒãã³ã¹ãèæ
®ããåžžã«ãŠãŒã¶ãŒãšã¯ã¹ããªãšã³ã¹ãåªå
ããããšãå¿ããªãã§ãã ããã